package me.olook.netease.song.rank.mapper;

import me.olook.netease.song.rank.entity.WeiboUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface WeiboUserJpaDao extends JpaRepository<WeiboUser,String> {

    /**
     * 按粉丝数量查询微博用户
     * @param pageable
     * @return
     */
    Page<WeiboUser> findWeiboUserByAddBy(String addBy , Pageable pageable);

    /**
     * 查询所有搜索关键词
     * @return
     */
    @Query("SELECT DISTINCT u.addBy from WeiboUser u")
    List<String> findAllAddBy();

    /**
     * 分关键词统计用户数
     * @param addBy
     * @return
     */
    Long countByAddBy(String addBy);

    /**
     * 分关键词统计男女用户
     * @param addBy
     * @return
     */
    @Query("SELECT u.gender,count(u.gender) from WeiboUser u where u.addBy = :addBy GROUP BY u.gender")
    List<Object[]> countAddByAndGender(@Param("addBy") String addBy);

    /**
     * 粉丝区间计数
     * @param followersCount
     * @param followersCount2
     * @param addBy
     * @return
     */
    Long countWeiboUsersByFollowersCountBetweenAndAddByEquals(Integer followersCount, Integer followersCount2, String addBy);

    /**
     * 查找最近昨天至今天的数据
     * @param crtTime
     * @return
     */
    List<WeiboUser> findAllByCrtTimeAfterAndAddByEquals(Date crtTime, String addBy);
}
